#include<bits/stdc++.h>
using namespace std;
int a[100001],b[100001],d[100001],v[100001];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        int n,m,l,V,flag=0;
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]==0)flag=1;
        }
        for(int i=1;i<=m;i++){
            cin>>b[i];
        }
        if(flag==1){
            int ans=0,sum=0;
            for(int i=1;i<=n;i++){
                if(v[i]>V&&d[i]>=b[1]){
                    ans++;
                    sum=max(sum,d[i]);
                }
            }
            cout<<ans<<" ";
            if(ans=0)cout<<m;
            else{
                sum=0;
                for(int i=1;i<=m;i++){
                    if(b[i]>d[i])sum++;
                }
            }
            cout<<sum;
        }
        else cout<<0<<" "<<m;
        cout<<endl;
    }
    return 0;
}
